package com.glacier.yuyuan.gen.webapp.utils;

import com.glacier.common.support.utils.SpringContextHolder;
import com.glacier.yuyuan.gen.webapp.domain.GenFieldType;
import com.glacier.yuyuan.gen.webapp.service.GenFieldTypeService;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * date 2023-02-02 15:36
 *
 * @author glacier
 * @version 1.0
 */
public class FieldTypeUtils {

    private FieldTypeUtils() {
    }

    /**
     * 根据数据库类型 查找字段类型
     *
     * @param dbType
     * @return
     */
    public static Map<String, GenFieldType> genFieldTypeList(String dbType) {
        GenFieldTypeService fieldTypeService = SpringContextHolder.getBean(GenFieldTypeService.class);
        return fieldTypeService.findByDbType(dbType)
                .stream()
                .collect(Collectors.toMap(GenFieldType::getColumnType, type -> type));
    }
}
